//
//  CategoryListViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/24.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "CategoryListViewController.h"
#import "UIViewExt.h"
#import "HttpRequest.h"

@interface CategoryListViewController ()<UISearchBarDelegate>

@end
@implementation CategoryListViewController

{
   
    NSMutableArray*codeArray;
    NSMutableArray*contentArray;
    UITableView*table;
    
}
@synthesize mDelegate;
-(void)viewDidLoad{
    
    [super viewDidLoad];
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.view.backgroundColor=[UIColor whiteColor];
    self.title=@"选择类别";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-64) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    codeArray=[[NSMutableArray alloc]init];
    contentArray=[[NSMutableArray alloc]init];
    codeArray=self.code;
    contentArray=self.content;
    [table reloadData];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [contentArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(10, 55-0.40, ScreenWidth-20, 0.40)];
            lineLabel1.backgroundColor=qianhuiColor;
            [cell.contentView addSubview:lineLabel1];
        
        }
    if (indexPath.section == 0) {
        cell.textLabel.text = [contentArray objectAtIndex:indexPath.row] ;
        cell.textLabel.font=[UIFont systemFontOfSize:16];
    }
   
    
    
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if ([self.sat isEqualToString:@"DeliveryType"]) {
        [mDelegate DeliveryType:contentArray[indexPath.row] DeliveryTypeCode:codeArray[indexPath.row]];
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    if ([self.sat isEqualToString:@"DiscountRate"]) {
        [mDelegate DiscountRate:contentArray[indexPath.row] DiscountRateCode:codeArray[indexPath.row]];
        [self.navigationController popViewControllerAnimated:YES];
    }

    
    if ([self.sat isEqualToString:@"EarnestRate"]) {
        [mDelegate EarnestRate:contentArray[indexPath.row] EarnestRateCode:codeArray[indexPath.row]];
        [self.navigationController popViewControllerAnimated:YES];
    }

    if ([self.sat isEqualToString:@"companyName"]) {
        [mDelegate EarnestRate:contentArray[indexPath.row] EarnestRateCode:codeArray[indexPath.row]];
        [self.navigationController popViewControllerAnimated:YES];
    }
    if ([self.sat isEqualToString:@"OrderDocType"]) {
        [mDelegate OrderDocType:contentArray[indexPath.row] OrderDocTypeCodeStr:codeArray[indexPath.row]];
      
        [self.navigationController popViewControllerAnimated:YES];
    }

    
    
}

@end
